FROM php:7.4-fpm

# 将阿里云镜像源替换为默认的镜像源
RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list \
    && sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list

# 安装系统依赖
RUN apt-get update && apt-get install -y \
    curl \
    libonig-dev \
    libxml2-dev \
    libzip-dev \
    libpng-dev \
    libjpeg-dev \
    unzip \
    zip \
    git 

# 安装 PHP 扩展
RUN docker-php-ext-install \
    bcmath \
    ctype \
    fileinfo \
    json \
    mbstring \
    pdo \
    pdo_mysql \
    tokenizer \
    xml \
    zip    

# 配置 php
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini \
    && echo "date.timezone = Asia/Shanghai" >> /usr/local/etc/php/php.ini \
    && echo "memory_limit = 4096M" >> /usr/local/etc/php/php.ini \
    && echo "post_max_size = 32M" >> /usr/local/etc/php/php.ini \
    && echo "max_execution_time = 300" >> /usr/local/etc/php/php.ini \
    && sed -i 's@^.*slowlog.*$@slowlog = var/log/slow.log@' /usr/local/etc/php-fpm.d/www.conf \
    && sed -i 's@^.*request_slowlog_timeout.*$@request_slowlog_timeout = 50@' /usr/local/etc/php-fpm.d/www.conf \
    && sed -i 's@^.*request_terminate_timeout.*$@request_terminate_timeout = 300@' /usr/local/etc/php-fpm.d/www.conf

# 安装 composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
    && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

# 安装扩展：
RUN pecl install redis \
    && docker-php-ext-enable redis \
    && pecl install xlswriter \
    && docker-php-ext-enable xlswriter

# 安装 nodejs
RUN curl -o node.tar.gz https://nodejs.org/dist/latest-v14.x/node-v14.21.3-linux-x64.tar.gz \
    && tar -xzf node.tar.gz -C /usr/local --strip-components=1 \
    && rm node.tar.gz
 
ENV PATH="/usr/local/bin:${PATH}"
ENV NODE_ENV=development

# 安装 yarn
RUN npm install --global yarn
# 配置国内镜像源
RUN npm config set registry https://registry.npm.taobao.org
RUN yarn config set registry https://registry.npm.taobao.org    